package com.example.myproject.zebra.sdk;

import com.zebra.sdk.comm.Connection;
import com.zebra.sdk.comm.ConnectionException;
import com.zebra.sdk.comm.TcpConnection;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import com.zebra.sdk.printer.ZebraPrinterLanguageUnknownException;

import java.util.HashMap;
import java.util.Map;

public class SdkUse1 {
    public static void main(String[] args) throws  Exception {
        example1();
    }

    private static void example1(){
        //Connection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
           // connection.open();
            ZebraPrinter printer = ZebraPrinterFactory.getInstance(null);
            Map<Integer,String> vars = new HashMap<Integer,String>();
            vars.put(12,"John");
            vars.put(11,"Smith");
            printer.printStoredFormat("E:\\projects\\mayun\\springboot-self\\learn-core\\src\\main\\java\\com\\example\\myproject\\zebra\\sdk\\FORMAT.ZPL",vars);
            //connection.close();
        } catch (Exception e) {

            e.printStackTrace();
        }
    }

    private void example3() throws ConnectionException{
        Connection connection = new TcpConnection("192.168.1.32", TcpConnection.DEFAULT_ZPL_TCP_PORT);
        try {
            connection.open();
            ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
            Map<Integer, String> vars = new HashMap<Integer, String>();
            vars.put(12, "东风伟世通汽车饰件系统有限公司"); // Customer Name
            vars.put(11, "订单号"); // Invoice Number
            vars.put(13, "供应商名称"); // Vendor Name
            printer.printStoredFormat("E:FORMAT3.ZPL", vars);
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (ZebraPrinterLanguageUnknownException e) {
            e.printStackTrace();
        } finally {
            connection.close();
        }
   }

}
